package leetcode_301_400;

import com.sun.xml.internal.ws.message.ByteArrayAttachment;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class LeeCode_345 {
    public static void main(String[] args) {
        System.out.println(reverseVowels("hello"));
    }
    private static String reverseVowels(String s) {
        List<Integer> list = new ArrayList<>();
        Set<Character> set = new HashSet<>();
        set.add('a');
        set.add('e');
        set.add('i');
        set.add('o');
        set.add('u');
        set.add('A');
        set.add('E');
        set.add('I');
        set.add('O');
        set.add('U');
        char[] chars = s.toCharArray();
        int l = 0, r = chars.length - 1;
        while (l < r){
            while (l < r && !set.contains(chars[l])){
                l++;
            }
            while (l < r && !set.contains(chars[r])){
                r--;
            }
            if (l < r){
                char tmp = chars[l];
                chars[l] = chars[r];
                chars[r] = tmp;
                l++;
                r--;
            }
        }
        return new String(chars);

      /*  int l = 0, r = list.size() - 1;
        StringBuilder sb = new StringBuilder(s);
        while (l < r){
            char tmp = sb.charAt(list.get(l));
            sb.replace(list.get(l), list.get(l) + 1, "" + sb.charAt(list.get(r)));
            sb.replace(list.get(r), list.get(r) + 1, "" + tmp);
            l++;
            r--;
        }
        return sb.toString();*/
    }
}
